package com.mdhw.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 在线接口文档
 * @author zhouxt
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

    @Value("${swagger.show}")
    private boolean swaggerShow;

    private static final List<String> appUrlPrefix = Arrays.asList(
    );

    @Bean
    public Docket sysApi() {

        ParameterBuilder ticketPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<>();
        ticketPar.name("Authorization").description("请求token")
                .modelRef(new ModelRef("string")).parameterType("header")
                //header中的ticket参数非必填，传空也可以
                .required(false).build();
        pars.add(ticketPar.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swaggerShow)
                .groupName("盲盒ERP系统后台")
                .globalOperationParameters(pars)
                .apiInfo(new ApiInfoBuilder()
                        .title("盲盒ERP系统后台API")
                        .version("1.0")
                        .build()
                )
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mdhw"))
                .paths((s) -> {
                    for (String urlPrefix : appUrlPrefix) {
                        if (StringUtils.startsWithIgnoreCase(s, urlPrefix)) {
                            return false;
                        }
                    }
                    return true;
                })
                .build();
    }




}
